package com.face.console.controller;

import com.face.console.pojo.dto.MenuDto;
import com.face.console.pojo.vo.InitAdminVO;
import com.face.console.service.AdminMenuService;
import com.face.console.service.MenuService;
import com.face.console.tools.BaseControoler;
import com.face.console.tools.Error;
import com.face.console.tools.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Description:
 * <p>
 * Created by Andy_Lau on 2020/12/17 17:20
 */

@RestController
@RequestMapping(value = "/api/menu")
public class MenuController extends BaseControoler {

    @Autowired
    private MenuService menuService;
    @Autowired
    private AdminMenuService adminMenuService;



    /**
     * 查询所有菜单
     * @return
     */
    @PostMapping(value = "/list")
//    @JwtIgnore
    public R queryAll() {
        return success(menuService.queryMenuList());
    }

    /**
     * 递归查询所有目录及菜单以树结构返回
     * @param id 0
     * @return
     */
    @GetMapping(value = "/{id}/list")
    public InitAdminVO querypidMenuById(@RequestParam("id") Long id) {
        System.out.println("id:  " + id);
        if (id==null) {
            return null;
        }
        return adminMenuService.querypidMenuById(id);
    }

    /**
     * admin-layui-查询所有菜单
     * @return
     */
    @GetMapping(value = "/admin/list")
    public R queryAdminMenuAll() {
        return success(adminMenuService.queryMenuList());
    }


    /**
     * 保存和编辑菜单
     * @param request
     * @return
     */
    @PostMapping(value = "/save")
    public R saveMenu(MenuDto request) {
        System.out.println("request: "+request);
        if (request == null) {
            return R.error(Error.参数为空异常);
        }
        menuService.saveMenu(request);
        return R.success();
    }

    /**
     * 获取一个菜单详情
     * @param
     * @return
     */
    @PostMapping(value = "/{id}/details")
    public  R queryMenuById(@RequestParam("id") Long id){
        return R.success(adminMenuService.queryMenuById(id));
    }

    /**
     * 删除一个菜单
     * @param
     * @return
     */
    @PostMapping(value = "/{id}/del")
    public  R delMenuById(@RequestParam("id") Long id){
        return R.success(adminMenuService.delById(id));
    }
}
